<template>
	<view>
		<view>
			<form @submit="formSubmit" @reset="formReset">
				<view class="uni-form-item uni-column">
					<view class="title">活动标题</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="name" placeholder="请输入活动标题" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">活动类型</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="activity_type_name" placeholder="请输入活动类型" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">活动地点</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="location" placeholder="请输入活动地点" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">广告</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="ad" placeholder="请输入广告" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">活动人数</view>
					<slider max="300" v-bind:value="size" name="slider" show-value></slider>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">活动负责人</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="user_name" placeholder="请输入活动负责人姓名" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">负责人电话</view>
					<input style="background-color: #F5F5F5;" maxlength="20" class="uni-input" name="input" v-model:value="user_phone" placeholder="请输入活动负责人电话" />
				</view>
				
				<view class="uni-list">
					<view class="uni-list-cell">
						<view class="uni-list-cell-left">
							开始日期
						</view>
						<view class="uni-list-cell-db">
							<picker mode="date" :value="dateStart" @change="bindDateChangeStart">
								<view class="uni-input">{{dateStart}}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="uni-list">
					<view class="uni-list-cell">
						<view class="uni-list-cell-left">
							结束日期
						</view>
						<view class="uni-list-cell-db">
							<picker mode="date" :value="dateEnd" @change="bindDateChangeEnd">
								<view class="uni-input">{{dateEnd}}</view>
							</picker>
						</view>
					</view>
				</view>

				<view class="poster-upload">
					<view class="poster">
						<image src="../../static/activity-img/20207281359468725.jpg" mode=""></image>
					</view>
					<button class="mini-btn" type="primary" size="mini" @click="clickUpload">选择图片</button>
				</view>	
				
				<view class="uni-form-item uni-column">
					<view class="title">对外状态</view>
					<radio-group name="radio" :value="show_status">
						<label>
							<radio value="0" /><text>公开</text>
						</label>
						<label>
							<radio value="1" /><text>半公开</text>
						</label>
						<label>
							<radio value="2" /><text>私人</text>
						</label>
					</radio-group>
				</view>
				

				<view class="uni-btn-v">
					<button form-type="submit" @click="publish">提交</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>

	export default {
		data(){
			const currentDateStart = this.getDateStart({
				format: true
			})
			const currentDateEnd = this.getDateEnd({
				format: true
			})
			return {
				dateStart: currentDateStart,
				dateEnd: currentDateEnd,
				name:"",
				activity_type_name:"",
				location:"",
				size:"80",
				ad:"",
				user_name:"",
				user_phone:"",
				show_status:"",
			}
			
		},
		methods:{
			async publish(){
				const res = await this.$myRequest({
					url: '/acp-activity/acpActivity/release',
					method: 'POST',
					data:{
						"name":this.name,
						"activityTypeName":this.activity_type_name,
						"location":this.location,
						"size":this.size,
						"userName":this.user_name,
						"userPhone":this.user_phone,
						"showStatus":"1",
						"startTime":"",
						"endTime":"",
						"activityTypeId":1,
						"activityTypeName":this.activity_type_name,
						"staffId":1,
						"staffName":"admin",
						"topic":this.name,
						"description":"描述",
						"poster":"/static/activity-img/timg-b.jpg",
						"ad":"广告",
						"userId":1,
						"userType":0,
						"signUpNum":1,
						"status":0,
						"code":"diyibu",
						"ad":this.ad,
					}
				})
				alert("发布成功")
			},
        bindDateChangeStart: function(e) {
            this.dateStart = e.target.value
        },
		bindDateChangeEnd: function(e) {
		    this.dateEnd = e.target.value
		},
        getDateStart(type) {
            const dateStart = new Date();
            let year = dateStart.getFullYear();
            let month = dateStart.getMonth() + 1;
            let day = dateStart.getDate();

            month = month > 9 ? month : '0' + month;;
            day = day > 9 ? day : '0' + day;
            return `${year}-${month}-${day}`;
        },
		getDateEnd(type) {
		    const dateEnd = new Date();
		    let year = dateEnd.getFullYear();
		    let month = dateEnd.getMonth() + 1;
		    let day = dateEnd.getDate();
		
		    month = month > 9 ? month : '0' + month;;
		    day = day > 9 ? day : '0' + day;
		    return `${year}-${month}-${day}`;
		},
		//上传图片
		clickUpload() {
			let _self = this;
			uni.chooseImage({
				count: 1,
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album'], //从相册选择
				success: (chooseImageRes) => {
					// console.log(chooseImageRes);
					const tempFilePaths = chooseImageRes.tempFilePaths;
					// console.log(tempFilePaths[0]);
					_self.IMGS = tempFilePaths[0];
					uni.showLoading({
						title:'正在上传'
					});
					const uploadTask = uni.uploadFile({
						url: 'api/index/upload',
						filePath: tempFilePaths[0],
						name: 'file',
						formData: {
							"user":'test'
						},
						success: (res) => {
							console.log((JSON.parse(res.data)).data);
							uni.hideLoading();
							uni.showToast({
								title:'上传成功',
								icon:'none',
								duration:2000
							});
							uni.setStorageSync('yuzhe_papers_image', (JSON.parse(res.data)).data);
						},
						fail: (error) => {
							console.log('失败原因',error);
						}
					});
				}
			});
		},
		
		
		
		}
	}
</script>

<style lang="scss">
    .uni-form-item .title {
        padding: 20rpx 0;
    }
</style>
